package cn.yuitstyle.fss.minio.starter;

import cn.yuitstyle.fss.minio.starter.config.MinioConfig;
import cn.yuitstyle.fss.minio.starter.util.MinioBucketUtils;
import cn.yuitstyle.fss.minio.starter.util.MinioFileService;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @author yuwg
 */
@Configuration
@EnableConfigurationProperties(MinioConfig.class)
@Import({MinioBucketUtils.class, MinioFileService.class})
public class MinioAutoConfiguration {

    @Autowired
    private MinioConfig minioConfig;

    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(minioConfig.getUrl())
                .credentials(minioConfig.getAccessKey(), minioConfig.getSecretKey())
                .build();
    }
}
